package com.yml.ktbus

import com.yml.ktbus.core.LiveEvent
import com.yml.ktbus.core.LiveEventBusCore
import com.yml.ktbus.core.Observable


/**
 * _     _           _____                _  ______
 * | |   (_)         |  ___|              | | | ___ \
 * | |    ___   _____| |____   _____ _ __ | |_| |_/ /_   _ ___
 * | |   | \ \ / / _ \  __\ \ / / _ \ '_ \| __| ___ \ | | / __|
 * | |___| |\ V /  __/ |___\ V /  __/ | | | |_| |_/ / |_| \__ \
 * \_____/_| \_/ \___\____/ \_/ \___|_| |_|\__\____/ \__,_|___/
 *
 *
 *
 * Created by yml on 2023/10/21.
 */
class LiveEventBus {

    companion object {

        /**
         * get observable by key with type
         *
         * @param key key
         * @param type type
         * @param <T> T
         * @return Observable
         */
        fun <T> get(key: String, type: Class<T>): Observable<T> {
            return LiveEventBusCore.get().with(key, type) as Observable<T>
        }

        /**
         * get observable by key
         *
         * @param key String
         * @param <T> T
         * @return Observable<T>
         */
        fun <T> get(key: String): Observable<T> {
            return LiveEventBusCore.get().with(key, Any::class.java) as Observable<T>
        }

        /**
         * get observable from eventType
         *
         * @param eventType Class
         * @param <T> T
         * @return Observable<T>
         */
        fun <T : LiveEvent?> get(eventType: Class<T>): Observable<T>? {
            return LiveEventBusCore.get().with(eventType.name, eventType)
        }

    }
}